package com.suse.ecommerce.serviceImp;

import com.suse.ecommerce.dao.UserMapper;
import com.suse.ecommerce.pojo.User;
import com.suse.ecommerce.pojo.UserExample;
import com.suse.ecommerce.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class UserServiceImpl implements UserService {
    @Autowired
    private UserMapper userMapper;
    /*
        检查用户登录信息，根据phone和password作为查询条件，有数据返回不包含密码的user，没有则返回null
     */
    @Override
    public User checkLoginInfo(String phone,String password) {
        UserExample example=new UserExample();
        UserExample.Criteria criteria = example.createCriteria();
        criteria.andPhoneEqualTo(phone);
        criteria.andPasswordEqualTo(password);
        List<User> users = userMapper.selectByExample(example);
        if(users.size()==0){
            return null;
        }
        User user = users.get(0);
        user.setPassword(null);
        return user;
    }

//    根据id查询用户
    @Override
    public User getUseById(int id) {
        return userMapper.selectByPrimaryKey(id);
    }
}
